package saxion.speelveld.spaceengineer.model;

import java.io.Serializable;
import java.util.ArrayList;

import saxion.speelveld.spaceengineer.buildings.Factory;
import saxion.speelveld.spaceengineer.buildings.GreenHouse;
import saxion.speelveld.spaceengineer.buildings.MeatLab;
import saxion.speelveld.spaceengineer.buildings.Mines;
import saxion.speelveld.spaceengineer.buildings.OreRefinery;
import saxion.speelveld.spaceengineer.buildings.Powerplant;
import saxion.speelveld.spaceengineer.buildings.RecreationCenter;
import saxion.speelveld.spaceengineer.buildings.ResearchLab;
import saxion.speelveld.spaceengineer.buildings.SolarCenter;
import saxion.speelveld.spaceengineer.buildings.SpaceCenter;
import saxion.speelveld.spaceengineer.buildings.SpaceCube;
import saxion.speelveld.spaceengineer.buildings.SpaceMarket;
import saxion.speelveld.spaceengineer.buildings.SpaceSchool;
import saxion.speelveld.spaceengineer.buildings.WareHouses;
import saxion.speelveld.spaceengineer.buildings.WaterPurificator;

public class Building implements Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1380208259853374108L;

	private String buildingName;

	private String buildingExplanation;

	private int buildingLevel;

	public ArrayList<Resource> resourceCosts;

	public int[] resourceImages;

	private int previewResourceImageId;

	private int Width;

	private int Height;

	// should be changed when house is build
	// private boolean connectedRight, connectedLeft, connectedTop, connectedBottom;

	// het gebouw is gebouwd wanneer deze var op 0 staat apparte variabel voor de status is dus overbodig.
	private int buildTimeLeft;

	// MS 16-03: bad ass.. sorry :o
	private int buildingPointInFieldX;

	private int buildingPointInFieldY;

	private int buildingId;

	private boolean connectedToSpaceCenter;

	public Building(int Width, int Height)
	{
		this.Width = Width;
		this.Height = Height;
		resourceCosts = new ArrayList<Resource>();
		resourceImages = new int[Width * Height];
		if (buildingLevel == 0)
		{
			buildingLevel = 1;
		}
	}

	public int getPreviewResourceImageId()
	{
		return previewResourceImageId;
	}

	public void setPreviewResourceImageId(int previewResourceImageId)
	{
		this.previewResourceImageId = previewResourceImageId;
	}

	public int getImageID(int placex, int placey)
	{
		return resourceImages[placex + placey * Width];
	}

	public int getWidth()
	{
		return this.Width;

	}

	public int getHeight()
	{
		return this.Height;
	}

	public void setHeight(int height)
	{
		this.Height = height;
	}

	public String getBuildingName()
	{
		return buildingName;
	}

	public void setBuildingName(String buildingName)
	{
		char[] buildingNameCharacters = buildingName.toCharArray();
		for (int index = 1; index < buildingNameCharacters.length; index++)
		{
			if (Character.isUpperCase(buildingNameCharacters[index]))
			{
				if (!Character.isWhitespace(buildingNameCharacters[index - 1]))
				{
					buildingName = buildingName.substring(0, index) + " " + buildingName.substring(index);
				}
			}
		}
		this.buildingName = buildingName;
	}

	public String getBuildingExplanation()
	{
		return buildingExplanation;
	}

	public void setBuildingExplanation(String buildingExplanation)
	{
		this.buildingExplanation = buildingExplanation;
	}

	public int getBuildingLevel()
	{
		return buildingLevel;
	}

	public void upgradeBuildingLevel()
	{
		this.buildingLevel = this.buildingLevel + 1;
	}

	public void setBuildingLevel(int buildingLevel)
	{
		this.buildingLevel = buildingLevel;
	}

	public int getBuildTimeLeft()
	{
		return buildTimeLeft;
	}

	public void setBuildTimeLeft(int buildTimeLeft)
	{
		this.buildTimeLeft = buildTimeLeft;
	}

	public void minusBuildTimeLeft(int minusBuildTime)
	{
		int setTime = this.buildTimeLeft - minusBuildTime;
		if (setTime >= 0)
		{
			setBuildTimeLeft(setTime);
		}
	}

	public boolean isConnectedToSpaceCenter()
	{
		return connectedToSpaceCenter;
	}

	public void setConnectedToSpaceCenter(boolean connectedToSpaceCenter)
	{
		this.connectedToSpaceCenter = connectedToSpaceCenter;
	}

	public static ArrayList<Building> GetAllDifferentBuildings()
	{
		ArrayList<Building> buildingList = new ArrayList<Building>();
		Factory factory = new Factory();
		buildingList.add(factory);
		GreenHouse greenhouse = new GreenHouse();
		buildingList.add(greenhouse);
		MeatLab meatlab = new MeatLab();
		buildingList.add(meatlab);
		Mines mines = new Mines();
		buildingList.add(mines);
		OreRefinery oreRefinery = new OreRefinery();
		buildingList.add(oreRefinery);
		Powerplant powerplant = new Powerplant();
		buildingList.add(powerplant);
		RecreationCenter recreationCenter = new RecreationCenter();
		buildingList.add(recreationCenter);
		ResearchLab researchLab = new ResearchLab();
		buildingList.add(researchLab);
		SolarCenter solarCenter = new SolarCenter();
		buildingList.add(solarCenter);
		SpaceCenter spaceCenter = new SpaceCenter();
		buildingList.add(spaceCenter);
		SpaceCube spaceCube = new SpaceCube();
		buildingList.add(spaceCube);
		SpaceMarket spaceMarket = new SpaceMarket();
		buildingList.add(spaceMarket);
		SpaceSchool spaceSchool = new SpaceSchool();
		buildingList.add(spaceSchool);
		WareHouses wareHouses = new WareHouses();
		buildingList.add(wareHouses);
		WaterPurificator waterPurificator = new WaterPurificator();
		buildingList.add(waterPurificator);
		return buildingList;
	}

	public int getBuildingPointInFieldX()
	{
		return buildingPointInFieldX;
	}

	public void setBuildingPointInFieldX(int buildingPointInFieldX)
	{
		this.buildingPointInFieldX = buildingPointInFieldX;
	}

	public int getBuildingPointInFieldY()
	{
		return buildingPointInFieldY;
	}

	public void setBuildingPointInFieldY(int buildingPointInFieldY)
	{
		this.buildingPointInFieldY = buildingPointInFieldY;
	}

	public int getBuildingId()
	{
		return buildingId;
	}

	public void setBuildingId(int buildingId)
	{
		this.buildingId = buildingId;
	}

}
